package com.heima.admin.controller.v1;

import com.heima.apis.admin.AdChannelControllerApi;

import com.heima.common.exception.CustException;
import com.heima.model.admin.dtos.AdChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.admin.service.AdChannelService;
import com.heima.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 96558
 * @Date 2021/1/8 19:11
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService channelService;
    @ApiOperation(value = "查询频道列表分页")
    @PostMapping("/list")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody AdChannelDto dto) {
        return channelService.findByNameAndPage(dto);
    }
    @ApiOperation(value = "新增")
    @PostMapping("/save")
    @Override
    public ResponseResult insert(@RequestBody AdChannel channel) {
        return channelService.insert(channel);
    }
    @ApiOperation(value = "修改")
    @PostMapping("/update")
    @Override
    public ResponseResult update(@RequestBody AdChannel adchannel) {
        return channelService.update(adchannel);
    }
    @ApiOperation(value = "删除")
    @GetMapping("/del/{id}")
    @Override
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
       return channelService.deleteById(id);
    }

    /**
     * 查询所有频道
     *
     * @return
     */
    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list=channelService.list();
        return ResponseResult.okResult(list);
    }


}
